<?php
    require_once "weixin_info.php";//微信授权获取用户头像等信息
    require_once "config.php";




require_once "WxPay.php";
$WxPay = new WxPay();
	if($_SERVER['REQUEST_METHOD'] == 'POST'){
        $money = $_POST['money'];
        $is_vip = $_POST['is_vip'];
        $type = $_POST['type'];
		$time = time();
		$order_num = $time.$_SESSION['Member_info'][0]['id'];

        $trade_no = mt_rand(1000000000,9999999999);
        $Result = $WxPay->SubmitJsApiUnifiedOrder('吉事多', $trade_no, $money);
        $SignParam = $WxPay->signJsApiPrepayParam($Result['prepay_id']);

		$or_sql = "INSERT INTO dyspw_order(order_name, uid, order_money, order_type ,order_status,order_time,order_num,is_vip, recharge_type) VALUES ('个人充值', '".$_SESSION['Member_info'][0]['id']."', '".$money."','微信支付', 1, '".$time."','".$order_num."','".$is_vip."','".$type."')";
		if(!empty($or_sql)){
			$result['status'] = 'y';

			echo   json_encode($result);
			exit();
		}else{
			$result['status'] = 'n';
			$result['info'] = '表单提交失败，请重新提交';
			echo   json_encode($result);
			exit();
		}
	}



 ?>

<!doctype html>

<html>

<head>

	<meta charset="utf-8">

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">

	<title>充值</title>

	<link rel="stylesheet" href="css/core.css">

	<script src="js/jquery-2.2.4.min.js" type="text/javascript"></script>

	<script src="js/jquery.cookie.js" type="text/javascript"></script>

	<script src="js/layer/layer.js" type="text/javascript"></script>

<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cb5d49b07e0a753dc8ee27ba2c73495d";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
</head>

<body>

    <section style="padding-bottom:60px;">

    	<div class="main" style="width:90%;">

    		<div class="recharge-user-info">

    			<img src="<?php echo $_SESSION['Member_info'][0]['avatar'] ?>" />

    			<p><?php echo $_SESSION['Member_info'][0]['username'] ?></p>

    			<i>会员到期日：2020.10.10</i>

    		</div>

    	</div>

    		<div class="recharge-list-box cl">

    			<ul class="recharge-menu-box cl">

    				<li class="cur">个人版</li>

    				<li>企业版</li>

    			</ul>

    			<div class="recharge-content-box">

    				<div class="content-items cl" style="display:block;">

    					<div class="items-box lxby fl">
    						<h2>包月</h2>
    						<p class="real-money">￥<em>9.9</em></p>
                            <input type="hidden" name="money" value="9.9">
                            <input type="hidden" name="is_vip" value="2">
                            <input type="hidden" name="type" value="month">
    						<p class="market-money">38元/月</p>
    					</div>

    					<div class="items-box fr">
    						<h2 style="margin-top:8px;">包年</h2>
    						<p class="real-money">￥<em>60</em></p>
                            <input type="hidden" name="money" value="60">
                            <input type="hidden" name="is_vip" value="2">
                            <input type="hidden" name="type" value="year">
    					</div>

    				</div>

    				<div class="content-items cl">

    					<div class="items-box lxby fl">

    						<h2>包月</h2>

    						<p class="real-money">￥<em>380</em></p>

    						<p class="market-money">680元/月</p>

    					</div>

    					<div class="items-box fr">

    						<h2 style="margin-top:8px;">包年</h2>

    						<p class="real-money">￥<em>2280</em></p>

    					</div>

    				</div>

    			</div>

    		</div>

    	<div class="main" style="width:80%;">

    		<div class="recharge-desc-box">

    			<p>说明：</p>

    			<p>个人版：支付9.9元成为个人会员即可享受商品展示等功能、个人主页展示；</p>
    			<p>企业版：支付380元成为企业会员即可享受商品展示购买、个人中心展示商铺等功能。</p>

    		</div>

    		<div class="recharge-footer-box">

    			<p><label><i></i>我已阅读并同意<a href="#">服务条款</a>及<a href="#">隐私协议</a></label></p>

    			<button class="recharge-btn">确认充值</button>

    		</div>

    	</div>

    </section>

<footer style="background-color:#FFF;">
    <ul class="cl">
        <li><a href="index.php">首页</a></li>
        <li><a href="fenlei.php">分类</a></li>
        <li><a href="baishe.php">拍</a></li>
        <li><a href="shopping.php">商城</a></li>
        <li><a href="member.php">我</a></li>
    </ul>
</footer>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript">



$(function(){

    $(".recharge-menu-box li").click(function(){
		$(this).addClass("cur").siblings().removeClass("cur");
		$(".recharge-content-box").find(".content-items").hide().eq($(this).index()).show();
	});



	$(".content-items .items-box").click(function(){
		$(this).addClass("cur").siblings().removeClass("cur");
	})


	$(".recharge-footer-box label").click(function(){
		if($(this).hasClass("cur")){
			$(this).removeClass("cur");
		}else{
			$(this).addClass("cur")
		}

	});



	$(".recharge-btn").click(function(){
		if($(".recharge-list-box").find(".cur").length == 0){
			return layer.open({content:"请选择充值类型",skin:'msg',time:3});
		}

		if(!$(".recharge-footer-box label").hasClass("cur")){
			return layer.open({content:"请同意服务条款及隐私协议",skin:'msg',time:3});
		}
        var money = $(".cur").find('input[name="money"]').val();
        var is_vip = $(".cur").find('input[name="is_vip"]').val();
        var type = $(".cur").find('input[name="type"]').val();
		$.ajax({
			url : "recharge.php",
			type: "post",
			data:{'money':money, 'is_vip':is_vip, 'type':type},
			dataType:'JSON',
			success:function(data){
				if(data.status == 'y'){
					WeixinJSBridge.invoke(
						'getBrandWCPayRequest',
						{
							"appId" : '<?php echo $SignParam['appId']; ?>',
							"timeStamp" : '<?php echo $SignParam['timeStamp']; ?>',
							"nonceStr" : '<?php echo $SignParam['nonceStr']; ?>',
							"package" : '<?php echo $SignParam['package']; ?>',
							"signType" : '<?php echo $SignParam['signType']; ?>',
							"paySign" : '<?php echo $SignParam['paySign']; ?>',
						},

						function(ret){
							if(ret.err_msg == "get_brand_wcpay_request:cancel"){
								layer.open({content:"您已取消了此次支付",skin:'msg',time:3});
							}else if(ret.err_msg == "get_brand_wcpay_request:fail"){
								layer.open({content:"支付失败，请重新尝试",skin:'msg',time:3});
							}else if(ret.err_msg == "get_brand_wcpay_request:ok"){
								<?php $Up_sql = "Update dyspw_member set is_vip = 2 where id = ".$_SESSION['Member_info'][0]['id'];
								$add_memshop = mysqli_query($mysql, $Up_sql); ?>
								layer.open({content:"支付成功,等待审核",skin:'msg',time:3});

								location.href = 'member.php';//跳转支付成功页面
							}else{
								layer.open({content:"未知错误"+ret.err_msg,skin:'msg',time:3});
							}
						}
					);
				}else{
					return layer.open({content:data.info,skin:'msg',time:3});
				}
			}
		})

	});

});



</script>

</body>

</html>
<?php

 ?>
